// bbldc_terminateddaycountutil.cpp                                   -*-C++-*-
#include <bbldc_terminateddaycountutil.h>

#include <bsls_ident.h>
BSLS_IDENT_RCSID(bbldc_terminateddaycountutil_cpp,"$Id$ $CSID$")

#include <bbldc_terminatedisda30360eom.h>

#include <bdlt_date.h>

#include <bsls_assert.h>

namespace BloombergLP {
namespace bbldc {

                      // -----------------------------
                      // struct TerminatedDayCountUtil
                      // -----------------------------

// CLASS METHODS
int TerminatedDayCountUtil::daysDiff(const bdlt::Date&        beginDate,
                                     const bdlt::Date&        endDate,
                                     const bdlt::Date&        terminationDate,
                                     DayCountConvention::Enum convention)
{
    int numDays;

    switch (convention) {
      case DayCountConvention::e_ISDA_30_360_EOM: {
        numDays = bbldc::TerminatedIsda30360Eom::daysDiff(beginDate,
                                                          endDate,
                                                          terminationDate);
      } break;
      default: {
        BSLS_ASSERT_OPT(0 && "Unrecognized convention");
        numDays = 0;
      } break;
    }

    return numDays;
}

bool TerminatedDayCountUtil::isSupported(DayCountConvention::Enum convention)
{
    bool rv = true;

    switch (convention) {
      case DayCountConvention::e_ISDA_30_360_EOM: {
      } break;
      default: {
        rv = false;
      } break;
    }

    return rv;
}

double TerminatedDayCountUtil::yearsDiff(
                                      const bdlt::Date&        beginDate,
                                      const bdlt::Date&        endDate,
                                      const bdlt::Date&        terminationDate,
                                      DayCountConvention::Enum convention)
{
    double numYears;

    switch (convention) {
      case DayCountConvention::e_ISDA_30_360_EOM: {
        numYears = bbldc::TerminatedIsda30360Eom::yearsDiff(beginDate,
                                                            endDate,
                                                            terminationDate);
      } break;
      default: {
        BSLS_ASSERT_OPT(0 && "Unrecognized convention");
        numYears = 0.0;
      } break;
    }

    return numYears;
}

}  // close package namespace
}  // close enterprise namespace

// ----------------------------------------------------------------------------
// Copyright 2016 Bloomberg Finance L.P.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------- END-OF-FILE ----------------------------------
